<?php

//Lấy ra tin
$db_news = new db_query('SELECT new_id,new_title,new_date,new_picture,new_teaser,new_detail,new_tags,new_relate,new_link,
                                    new_cat_id,cat_id,cat_name
                                FROM news 
                                LEFT JOIN categories_multi ON cat_id = new_cat_id 
                                WHERE new_id = '.$iNews.'
                                LIMIT 1');
$news = mysql_fetch_assoc($db_news->result);
unset($db_news);
$nums = strpos($news['new_link'],':');
if($nums > 0){
    $url_news = $news['new_link'];
}else{
    $url_news = 'http://'.$news['new_link'];
}
$url_parse = parse_url($url_news);

//update view
$db_update_view = new db_execute('UPDATE news SET new_view = new_view + 1 WHERE new_id = '.$news['new_id']);

//Đưa ra tin có thể quan tâm
$db_list_hot = new db_query('SELECT new_id,new_title,new_date,new_picture,new_teaser,new_detail,new_hot_home,new_active
                                cat_id,cat_name
                                FROM news 
                                LEFT JOIN categories_multi ON cat_id = new_cat_id 
                                WHERE new_hot_cat = 1 AND new_cat_id = '.$news['new_cat_id'].' AND new_id != '.$news['new_id'].' AND new_active = 1
                                ORDER BY new_date DESC 
                                LIMIT 3');
$list_hot = $db_list_hot->resultArray();
unset($db_list_hot);

//Đưa ra tin mới nhất của cat
$db_list_new = new db_query('SELECT new_id,new_title,new_date,new_picture,new_teaser,new_detail,new_tags,new_relate,new_link,
                                    new_cat_id,cat_id,cat_name
                                FROM news 
                                LEFT JOIN categories_multi ON cat_id = new_cat_id 
                                WHERE new_cat_id = '.$news['new_cat_id'].' AND new_id != '.$news['new_id'].' AND new_active = 1
                                ORDER BY new_date DESC 
                                LIMIT 10');
$list_new = $db_list_new->resultArray();
unset($db_list_new);
//Lấy ra tin mới nhất trong ngày
$date = date('d-m-Y',time());
$start =  strtotime($date);
$end =  $start + 84600;
$db_news_date = new db_query('SELECT new_id,new_title,new_date,new_picture,new_teaser,new_detail,new_tags,new_relate,new_link,
                                    new_cat_id,cat_id,cat_name
                                FROM news 
                                LEFT JOIN categories_multi ON cat_id = new_cat_id 
                                WHERE new_active = 1 AND new_cat_id != '.$news['new_cat_id'].' AND new_date BETWEEN '.$start .' AND '.$end.'
                                ORDER BY new_date DESC
                                LIMIT 10');
$news_date = $db_news_date->resultArray();
unset($db_news_date);
//Đưa ra tin đọc nhiều nhất - cùng categories - cách thời điểm truy cập 6 tiếng (tin xem nhiều trong 6 tiếng vừa qua)
$time_view = time() - 36*3600;
$db_list_view = new db_query('SELECT new_id,new_title,new_date,new_picture,new_teaser,new_detail,new_tags,new_relate,new_link,
                                    new_cat_id,cat_id,cat_name
                                FROM news 
                                LEFT JOIN categories_multi ON cat_id = new_cat_id 
                                WHERE new_date >= '.$time_view.' AND new_cat_id = '.$news['new_cat_id'].' AND new_id != '.$news['new_id'].'  AND new_active = 1
                                ORDER BY new_view DESC 
                                LIMIT 10');
$list_view = $db_list_view->resultArray();
unset($db_list_view);

//Lấy ra bình luận của tin
$db_list_comments = new db_query('SELECT * FROM comments WHERE com_news_id = '.$iNews.' AND com_active = 1 LIMIT 5');
$list_comments = $db_list_comments->resultArray();
unset($db_list_comments);
?>